package com.dom.domweb.modular.controller.sysmger;

import com.dom.common.model.vo.basic.B140R;
import com.dom.common.model.vo.basic.B143A;
import com.dom.common.model.vo.basic.B149A;
import com.dom.common.model.vo.basic.B149R;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.dao.entity.TGoodsInfo;
import com.dom.domweb.dao.service.ITGoodsInfoService;
import com.dom.domweb.modular.service.GoodsService;
import com.dom.domweb.modular.shiro.model.ShiroUser;
import com.dom.domweb.modular.shiro.util.ShiroUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 商品控制层逻辑
 * @Author xllei
 * @Date 2018/12/15 3:29 PM
 * @Version 1.0
 **/
@RestController
@RequestMapping("/sys")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private ITGoodsInfoService goodsInfoService;

    @RequestMapping("/getGoodsList")
    public RspModel getGoodsList(){
        ShiroUser user = ShiroUtil.getUser();

        List<TGoodsInfo> goodsInfos = goodsService.getGoodsList(user);
        return new RspModel(goodsInfos);
    }

    @RequestMapping("/getGoodsInfoList")
    public TabPager getGoodsInfoList(@RequestParam("limit")int limit, @RequestParam("page")int page){
        B149R request = new B149R();
        request.setPn(page);
        request.setPs(limit == 0 ? 20 : limit);
        B149A result = goodsInfoService.getGoodsInfoList(request);
        return new TabPager(result.getGoodsData(),result.getTotalNum());
    }

    @RequestMapping("/getAllGoodsInfo")
    public RspModel getAllGoodsInfo(){
        B149A result = goodsInfoService.getAllGoodsInfo();
        return new RspModel(result.getGoodsData());
    }

    @RequestMapping("/getGoodsInfoByCode")
    public RspModel getGoodsInfoByCode(@RequestParam("goodsCode") String goodsCode){
        B143A result = goodsInfoService.getGoodsInfoByCode(goodsCode);
        return new RspModel(result);
    }
    @RequestMapping("/insertGoodsInfo")
    public RspModel insertGoodsInfo(@RequestBody B140R request){
        return goodsInfoService.insertGoodsInfo(request);
    }

    @RequestMapping("/updateGoodsInfo")
    public RspModel editGoodsInfo(@RequestBody B140R request){
        return goodsInfoService.editGoodsInfo(request);
    }

    @RequestMapping("/goodsInfoDel")
    public RspModel goodsInfoDel(@RequestParam("id")String id){
        return goodsInfoService.goodsInfoDel(id);
    }
}
